﻿<%@ Control Language="C#" AutoEventWireup="true" Inherits="Portal.Data.Webparts.WebpartControl" %>
<%@ Import Namespace="Portal.Core.Security" %>
<%@ Import Namespace="Portal.Data.Entity" %>
<div class="hot_nhat clear_fix">
    <div class="wrap_content clear_fix">
        <h1 class="tit_cate">
            <asp:Literal ID="ltrBookTitle" runat="server"></asp:Literal>
        </h1>
        <div class="gioi_thieu">
            <div class="share">
                <ul class="share-box">
                    <li class="fb-like-wrapper">
                        <div class="fb-like" data-href="<%=BookUrlAbsolute %>" data-width="135" data-layout="button_count" data-action="like" data-show-faces="true" data-share="true"></div>
                    </li>
                    <li class="g-plusone-wrapper">
                        <div class="g-plusone" data-size="medium" data-href="<%=BookUrlAbsolute %>"></div>
                    </li>
                </ul>
            </div>
            <div class="content-body">
                <div class="ten_muc">
                    <h2>
                        <asp:Literal ID="ltrTitle" runat="server"></asp:Literal>
                    </h2>
                </div>
                <!--END ten_muc-->
                <div class="tim_trang">
                    <ul>
                        <li class="nonefloat">
                            <input type="text" id="txtChapterTop" class="den_muc" />
                            <input type="button" id="btnGoChapTop" value=" Đến mục " style="float: right !important;width: 120px;"/>
                        </li>
                    </ul>
					<ul>
                        <li class="nonefloat">
                            <asp:DropDownList ID="cboChapListTop" DataTextField="Title"
                                DataValueField="URL" runat="server" onchange="window.location.href=this.options[this.selectedIndex].value;">
                            </asp:DropDownList>
                        </li>
                    </ul>
                    <ul>
                        <li>
                            <a href="<%=PrevPage %>">Chap trước</a>
                        </li>
                        <li class="rightfloat">
                            <a href="<%=NextPage %>" class="nextpage">Đọc chap tiếp theo</a>
                        </li>
                    </ul>                    
                </div>
                <!--END tim_trang-->
                <div class="nd_gt clear_fix">
                    <div class="nd_truyen">
                        <asp:Literal ID="ltrBody" runat="server"></asp:Literal>
                        <script type='text/javascript' src='http://truyengicungco.gsspcln.jp/sdk/t/21847.js'></script>
                    </div>
                </div>
                <!--END nd_gt-->
                <div class="tim_trang">
                   
                    <ul>
                        <li class="nonefloat">
                            <input id="txtChapter" type="text" class="den_muc"/>
                            <input type="button" id="btnViewChap" value=" Đến mục " style="float: right !important;width: 120px;"/>
                        </li>
                    </ul> 
					<ul>
                        <li class="nonefloat">
                            <asp:DropDownList ID="cboChapListBottom" DataTextField="Title"
                                DataValueField="URL" runat="server" onchange="window.location.href=this.options[this.selectedIndex].value;">
                            </asp:DropDownList>
                        </li>
                    </ul>
                    <ul>
                        <li>
                            <a href="<%=PrevPage %>">Chap trước</a>
                        </li>
                        <li class="rightfloat">
                            <a href="<%=NextPage %>" class="nextpage">Đọc chap tiếp theo</a>
                        </li>
                    </ul>
                </div>
                <!--END tim_trang-->
            </div>
        </div>
        <!--END gioi_thieu-->
		<div class="clear_fix"></div>
        <%if (!Portal.Core.Utils.MyCheck.IsMobileClient()){%>
        <div id="fb-block">
		<center>
            <div class="fb-comments" data-href="<%=BookUrlAbsolute%>" data-width="650" data-num-posts="5"></div>
			</center>
        </div>
        <%} %>
    </div>
</div>
<script type="text/javascript">
    jQuery(function ($) {
        var bid = '<%=BookId %>';
        $('#txtChapter').keyup(function (e) {
            var key = e.keyCode || e.which;
            if (key === 13) {
                goChap(bid, $(this).val());
            }
        });
        $('#txtChapterTop').keyup(function (e) {
            var key = e.keyCode || e.which;
            if (key === 13) {
                goChap(bid, $(this).val());
            }
        });
        $('#btnGoChapTop').click(function () {
            goChap(bid, $('#txtChapterTop').val());
        });
        $('#btnViewChap').click(function () {
            goChap(bid, $('#txtChapter').val());
        });

        preloadChap(bid, '<%=NextChapId%>');

        var np = '<%=NextPage%>';
        if (np.indexOf('##') >= 0) {
            $('.nextpage').html('[Hết Truyện]');
        } else if (np.indexOf('#') >= 0) {
            $('.nextpage').html('[chưa có chap mới]');
        }
        bookIncr(bid, '<%=ChapId%>');

        if (location.href.toLowerCase().indexOf('trang-quynh') >= 0)
            $('.nd_truyen').html("<div style='display: inline-block;margin: 50px 0;'>Truyện có bản quyền nên không thể xem ở đây. Các bạn hãy vào trang <a target=_blank href='http://truyentranhvang.com'>http://truyentranhvang.com</a> để theo dõi bộ này nhé</div>");
    });
</script>
<script runat="server">
    public string BookUrlAbsolute, Description, CategoryUrl, CategoryName, NextPage, PrevPage;
    public int BookId, ChapId, NextChapId;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ChapId = Convert.ToInt32(Common.GetViewId());
            if (ChapId == 0) throw new HttpNotFoundException();

            var content = Portal.Data.Entity.Content.FindByPrimaryKey(ChapId);
            if (content == null) throw new HttpNotFoundException();

            if (!content.URL.Equals(Request.RawUrl, StringComparison.OrdinalIgnoreCase))
            {
                Response.StatusCode = 301;
                Response.AddHeader("Location", content.URL);
                return;
            }
            var b = content.GetBook();
            if (b == null || !b.Status) throw new HttpNotFoundException();
            
            BookId = content.Book_ID;

            //binding list
            var listchap = Portal.Data.Entity.Content.FindByBook(content.Book_ID).OrderByDescending(x => x.Chapter);
            cboChapListTop.DataSource = listchap;
            cboChapListTop.DataBind();
            cboChapListTop.SelectedValue = content.URL;
            cboChapListBottom.DataSource = listchap;
            cboChapListBottom.DataBind();
            cboChapListBottom.SelectedValue = content.URL;

            //catche for next/back chap
            var next = Portal.Data.Entity.Content.FindNext(content.Book_ID, content.Chapter);
            var prev = Portal.Data.Entity.Content.FindPrevious(content.Book_ID, content.Chapter);
            
            PrevPage = prev != null ? prev.URL : "#";
            NextPage = next != null ? next.URL : "#";
            
            var book = Book.FindByPrimaryKey(content.Book_ID);
            if (book.Finish && NextPage.Length == 1 )
                NextPage= "##";
            
            ltrBookTitle.Text = string.Format("<a href='{0}' title='{1}'>{1}</a>", book.Url, book.FullName);
            BookUrlAbsolute = Portal.Core.Common.GetAbsoluteUrl(book.Url);

            Page.Title = book.FullName + @" > " + content.Title;

            ltrTitle.Text = content.Title;

            ltrBody.Text = content.GetBodyMobile();
//            ltrBody.Text = Portal.Core.Utils.MyCheck.IsMobileClient() ? content.GetBodyMobile() : content.GetBody();

            //meta
            var metatag = new LiteralControl
                              {
                                  Text =
                                      string.Format("<meta name='description' content='{0},{1}'/>", content.Title,
                                                    book.SeoDescription())
                              };
            Page.Header.Controls.Add(metatag);
        }
    }    


</script>
